package com.qf.talk.settings;

import com.qf.talk.dao.FriendShipPolicyDao;
import com.qf.talk.model.FriendShipPolicy;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 30909
 *  好友策略的配置方案
 */
public class FriendPolicySetting {

    private static Map<String,Integer> friendPolicySetting = new HashMap<>();





    @Resource
    private FriendShipPolicyDao friendShipPolicyDao;


    /**
     * 为了处理魔法值
     */

    public static final String POLICY_DESC_1 ="随即添加";
    public static final String POLICY_DESC_2 ="验证问题";
    public static final String POLICY_DESC_3 ="验证密码";
    public static final String POLICY_DESC_4 ="验证信息";
    public static final String POLICY_DESC_5 ="从不添加";

    /**
     * Java中该注解的说明：@PostConstruct该注解被用来修饰一个非静态的void（）方法。
     * 被@PostConstruct修饰的方法会在服务器加载Servlet的时候运行，并且只会被
     * 服务器执行一次。PostConstruct在构造函数之后执行，init（）方法之前执行。
     */
    @PostConstruct
    public void initSettings(){
        List<FriendShipPolicy> friendSkipPolicies = friendShipPolicyDao.selectByExample(null);
        for (int i = 0; i < friendPolicySetting.size(); i++) {
            friendPolicySetting.put(friendSkipPolicies.get(i).getDescription(),
                    friendSkipPolicies.get(i).getId());

        }
    }

    /**
     * 对外提供的方法
     * @param policyDesc
     * @return
     */
    public static int policyId(String policyDesc){
        return   friendPolicySetting.get(policyDesc);
    }


}
